# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License.  You may obtain a copy
# of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations
# under the License.

"""Utility Functions."""

import config
import datetime

from google.appengine.ext.webapp import template as webapp_template

def DisplayDate(d):
    return d.strftime(config.display_date_format)

def ParseDate(s):
    return datetime.datetime.strptime(s, config.parse_date_format)

def FormatDateForInput(d):
    return d.strftime(config.parse_date_format)

def DateNow():
    return datetime.datetime.now()


register = webapp_template.create_template_register()
register.filter('DisplayDate', DisplayDate)
register.filter('FormatDateForInput', FormatDateForInput)
webapp_template.django.template.builtins.append(register)
    # The reccomended method of adding custom filters, which would be to call
    #       webapp.template.register_template_library('utility')
    # appears busted in the version of AppEngine tested. This method is both
    # simpler, and works - though may break in the future.
